'use strict';

/**
 * copyright (c) 2017-2023 厦门风领科技有限公司
 * https://www.fengling.cn/
 * 
 * 初始化广告组件
 * zengbinsi
 * 2020-08-24
 */


import fs from 'fs';
import path from 'path';
import pathUtil from '../libs/utils/path-utils';
import fileUtil from '../libs/utils/file-utils';
import { callSequence } from '../libs/utils/function-call-seq';
const srcPath = pathUtil.getPathInTemplateAssets(path.join('bundles', 'framework', 'platform', 'ad'));
const dstPath = pathUtil.getPathInAssets(path.join('bundles', 'framework', 'platform', 'ad'));




// 初始化目录
const initDir = (callback?: Function) => {
    pathUtil.mkdirsSyncInAssets(path.join('bundles', 'framework', 'platform', 'ad'), callback);
};


export const initFilePlatformAD = (fileName: string, callback?: Function) => {
    console.log(`[tool-box]import ${fileName}.ts...`);
    return callSequence([initDir, async (cb?: Function) => {
        fs.existsSync(path.join(srcPath, `${fileName}.ts.meta`)) && fileUtil.copy(path.join(srcPath, `${fileName}.ts.meta`), path.join(dstPath, `${fileName}.ts.meta`));
        fileUtil.copy(path.join(srcPath, `${fileName}.tsz`), path.join(dstPath, `${fileName}.ts`));
        await pathUtil.refreshAsset(`db://assets/bundles/framework/platform/ad/`);
        console.log(`[tool-box]import ${fileName}.ts successed!`);
        cb && cb();
    }, callback]);
};